package com.example.zwh.computershop.order;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.zwh.computershop.Myapp;
import com.example.zwh.computershop.R;
import com.example.zwh.computershop.sqlModel.Order;

import java.util.ArrayList;

public class WaitingCommentFragment extends Fragment {
    private RecyclerView waiting_comment_order_list;
    private OrderAdapter orderAdapter;
    private ArrayList<Order> arrayList = new ArrayList<>();

    LinearLayout waiting_comment_order_empty;

    Myapp myapp;

    private View view;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_waiting_comment_order, container, false);
        initView();
        initData();
        System.out.println("代评论");
        return view;
    }

    void initView() {
        myapp = (Myapp) getActivity().getApplication();

        waiting_comment_order_list = view.findViewById(R.id.waiting_comment_order_list);
        waiting_comment_order_empty = view.findViewById(R.id.waiting_comment_order_empty);
        orderAdapter = new OrderAdapter(arrayList, myapp);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        waiting_comment_order_list.setLayoutManager(layoutManager);
        waiting_comment_order_list.setAdapter(orderAdapter);

    }

    void initData() {
        arrayList.clear();
        int len = myapp.getOra().size();
        for (int i = 0; i < len; i++) {
            if (myapp.getOra().get(i).getPayState() == 1 && myapp.getOra().get(i).getReceiveState() == 1) {
                arrayList.add(myapp.getOra().get(i));
            }
        }
        if (arrayList.size() != 0) {
            waiting_comment_order_list.setVisibility(View.VISIBLE);
            waiting_comment_order_empty.setVisibility(View.GONE);
        }else {
            waiting_comment_order_empty.setVisibility(View.VISIBLE);
            waiting_comment_order_list.setVisibility(View.GONE);
        }
    }
}
